
// C++
#include <vector>
using namespace std;

#include <sys/epoll.h>

#include "Poller.hpp"

#ifndef EPOLLPOLLER_HPP
#define EPOLLPOLLER_HPP

namespace tulun
{
    class EPollPoller : public tulun::Poller
    {
    public:
        using EventList = std::vector<struct epoll_event>;

    private:
        int epollfd_;
        EventList events_;

    public:
        EPollPoller(EventLoop *loop);
        virtual ~EPollPoller();
        virtual Timestamp poll(int timeoutMs, ChannelList *activeChannels);
        virtual void updateChannel(Channel *channel);
        virtual void removeChannel(Channel *channel);

    private:
        static const int kInitEventListSize = 16;
        void fillActiveChannels(int numEvents, ChannelList *activeChannels) const;
        void update(int operation, Channel *channel);
    };
} // namespace tulun

#endif